﻿namespace My.Hydrator.Tests.Formatters
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using My.Hydrator.Formatters;

    [TestClass]
    public class NumericDataTypeFormatterTests
    {
        [TestMethod]
        public void HydrationShouldPassForValidTypesOldNotation()
        {
            var hydrator = new Hydrator();

            hydrator.Configure(x =>
            {
                x.For("NumericInt").Use(new NumericDataTypeFormatter<int>(0, 100, "NumericInt"));
                x.For("NumericDouble").Use(new NumericDataTypeFormatter<double>(0.5, 15.2, "NumericDouble"));
                x.For("NumericFloat").Use(new NumericDataTypeFormatter<float>(2.3f, 3.9f, "NumericFloat"));
                x.For("NumericDecimal").Use(new NumericDataTypeFormatter<decimal>(-5.2m, -4.3m, "NumericDecimal"));
            });

            for (var i = 0; i < 25000; i++)
            {
                var result = hydrator.Hydrate<FormatterTestClass>();

                Assert.IsTrue(result.NumericInt >= 0 && result.NumericInt <= 100, string.Format("Int: {0} >= 0 && {0} <= 100", result.NumericInt));
                Assert.IsTrue(result.NumericDouble >= 0.5 && result.NumericDouble <= 15.2, string.Format("Double: {0} >= 0.5 && {0} <= 15.2", result.NumericDouble));
                Assert.IsTrue(result.NumericFloat >= 2.3f && result.NumericFloat <= 3.9f, string.Format("Float: {0} >= 2.3 && {0} <= 3.9", result.NumericFloat));
                Assert.IsTrue(result.NumericDecimal >= -5.2m && result.NumericDecimal <= -4.3m, string.Format("Decimal: {0} >= -5.2 && {0} <= -4.3", result.NumericDecimal));
            }
        }

        [TestMethod]
        public void HydrationShouldPassForValidTypesNewNotation()
        {
            var hydrator = new Hydrator();

            hydrator.Configure(x =>
            {
                x.For("NumericInt").UseNumeric(0, 100);
                x.For("NumericDouble").UseNumeric(0.5, 15.2);
                x.For("NumericFloat").UseNumeric(2.3f, 3.9f);
                x.For("NumericDecimal").UseNumeric(-5.2m, -4.3m);
            });

            for (var i = 0; i < 25000; i++)
            {
                var result = hydrator.Hydrate<FormatterTestClass>();

                Assert.IsTrue(result.NumericInt >= 0 && result.NumericInt <= 100, string.Format("Int: {0} >= 0 && {0} <= 100", result.NumericInt));
                Assert.IsTrue(result.NumericDouble >= 0.5 && result.NumericDouble <= 15.2, string.Format("Double: {0} >= 0.5 && {0} <= 15.2", result.NumericDouble));
                Assert.IsTrue(result.NumericFloat >= 2.3f && result.NumericFloat <= 3.9f, string.Format("Float: {0} >= 2.3 && {0} <= 3.9", result.NumericFloat));
                Assert.IsTrue(result.NumericDecimal >= -5.2m && result.NumericDecimal <= -4.3m, string.Format("Decimal: {0} >= -5.2 && {0} <= -4.3", result.NumericDecimal));
            }
        }
    }
}
